- Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathSegmentTreeClient.java
30 lines (20 loc) Β· 936 Bytes
/
SegmentTreeClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
packagesection21_SegmentTrees;
publicclassSegmentTreeClient {
publicstaticvoidmain(String[] args) {
int[] arr = { 3, 8, 7, 6, -2, -8, 4, 9 };
SegmentTreetree = newSegmentTree(arr);
tree.display();
System.out.println("\n------------------------------------------");
intrangeSum = tree.query(2, 6); // startIndex, endIndex of array
System.out.println("sum of array in range is: " + rangeSum); // 7
System.out.println("sum of array in range is: " + tree.query(4, 5)); // -10
System.out.println("sum of array in range is: " + tree.query(0, 0)); // 3
System.out.println("\nafter update operation...\n");
System.out.println("\n------------------------------------------");
intupdateIndex = 3, updateNewValue = 14;
tree.update(updateIndex, updateNewValue);
tree.display();
System.out.println("\n-------------");
System.out.println("sum of array in range is: " + tree.query(2, 6)); // 15
}
}